package com.ruoyi.web.controller.assets;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.RepairLog;
import com.ruoyi.system.service.IRepairLogService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 报修日志Controller
 * 
 * @author hzl
 * @date 2025-03-19
 */
@RestController
@RequestMapping("/assets/repairLog")
public class RepairLogController extends BaseController
{
    @Autowired
    private IRepairLogService repairLogService;

    /**
     * 查询报修日志列表
     */
    @PreAuthorize("@ss.hasPermi('assets:repairLog:list')")
    @GetMapping("/list")
    public TableDataInfo list(RepairLog repairLog)
    {
        startPage();
        List<RepairLog> list = repairLogService.selectRepairLogList(repairLog);
        return getDataTable(list);
    }

    /**
     * 导出报修日志列表
     */
    @PreAuthorize("@ss.hasPermi('assets:repairLog:export')")
    @Log(title = "报修日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RepairLog repairLog)
    {
        List<RepairLog> list = repairLogService.selectRepairLogList(repairLog);
        ExcelUtil<RepairLog> util = new ExcelUtil<RepairLog>(RepairLog.class);
        util.exportExcel(response, list, "报修日志数据");
    }

    /**
     * 获取报修日志详细信息
     */
    @PreAuthorize("@ss.hasPermi('assets:repairLog:query')")
    @GetMapping(value = "/{repairApplicationId}")
    public AjaxResult getInfo(@PathVariable("repairApplicationId") Long repairApplicationId)
    {
        return success(repairLogService.selectRepairLogByRepairApplicationId(repairApplicationId));
    }

    /**
     * 新增报修日志
     */
    @PreAuthorize("@ss.hasPermi('assets:repairLog:add')")
    @Log(title = "报修日志", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RepairLog repairLog)
    {
        return toAjax(repairLogService.insertRepairLog(repairLog));
    }

    /**
     * 修改报修日志
     */
    @PreAuthorize("@ss.hasPermi('assets:repairLog:edit')")
    @Log(title = "报修日志", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RepairLog repairLog)
    {
        return toAjax(repairLogService.updateRepairLog(repairLog));
    }

    /**
     * 删除报修日志
     */
    @PreAuthorize("@ss.hasPermi('assets:repairLog:remove')")
    @Log(title = "报修日志", businessType = BusinessType.DELETE)
	@DeleteMapping("/{repairApplicationIds}")
    public AjaxResult remove(@PathVariable Long[] repairApplicationIds)
    {
        return toAjax(repairLogService.deleteRepairLogByRepairApplicationIds(repairApplicationIds));
    }
}
